<?php get_header(); ?>

    <?php 
        $page_type = mb_get_page_type();

        //var_dump($wp_query);
        // var_dump($page_type);

        switch ($page_type) {
            case 'category':
                $archive_title = __('Category', 'loc_canon');
                $archive_subject = single_cat_title('', false);
                break;
            case 'tag':
                $archive_title = __('Tag', 'loc_canon');
                $archive_subject = single_tag_title('', false);
                break;
            case 'search':
                global $query_string;
                query_posts( $query_string . '&post_type=post');
                $archive_title = __('Search', 'loc_canon');
                $archive_subject = get_search_query();
                break;
            case 'author':
                $archive_title = __('Author', 'loc_canon');
                $archive_subject = get_the_author_meta('display_name',$wp_query->post->post_author);
                break;
            case 'day':
                $archive_title = __('Day', 'loc_canon');
                $archive_subject =  get_the_time('d/m/Y');
                break;
            case 'month':
                $archive_title = __('Month', 'loc_canon');
                $archive_subject = get_the_time('m/Y');
                break;
            case 'year':
                $archive_title = __('Year', 'loc_canon');
                $archive_subject = get_the_time('Y');
                break;
            default:
                $archive_title = __('Browsing', 'loc_canon');
                $archive_subject = __('Unknown', 'loc_canon');
                break;
        }

        $excerpt_length = 370;

    ?>

		 <!-- Start Main Body -->
        <div class="main-container">
            <div class="main wrapper clearfix">
            	
          	<!-- Start Main Content -->
                <div class="main-content">
                	<div class="clearfix">
                		
                		<!-- Headings -->  
                		<h1><?php echo $archive_title; ?></h1>
                		<p class="lead"><?php _e('Your search for','loc_canon'); ?> <span class="highlight"><?php echo $archive_subject; ?></span> <?php _e('returned','loc_canon'); ?> <?php echo $wp_query->found_posts; ?> <?php if (count($wp_query->posts) !== 1) {_e('results','loc_canon');} else {_e('result','loc_canon');} ?>. </p>
                		
                        <!-- SEARCH FORM -->
                        <?php get_search_form(); ?>
                		
                		
                        <!-- MAIN LOOP -->
                        <?php while ( have_posts() ) : the_post(); ?>
                                    

                            <?php 
                                $result_cmb_excerpt = get_post_meta(get_the_ID(), 'cmb_excerpt', true); 
                                $the_excerpt = (!empty($result_cmb_excerpt)) ? do_shortcode($result_cmb_excerpt) :  mb_make_excerpt(get_the_content(), $excerpt_length, true);
                                $the_excerpt = mb_tag_search_string($the_excerpt, $archive_subject, "<span class='highlight'>","</span>", false);
                            ?>
                            
                            <hr/>
                               
                            <!-- Result -->
                            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                            <p><?php echo $the_excerpt; ?></p>
                            <p><a class="more" href="<?php the_permalink(); ?>"><?php _e('Read More','loc_canon'); ?></a>

                        <?php endwhile; ?>
                        <!-- END LOOP -->

                        <hr/>
               		
                        <!-- PAGINATION -->
                        <?php get_template_part("inc/templates/template_paginate_links"); ?>

					<!-- Finish Main Content -->
                	</div>    
                </div>
				
				
                <!-- SIDEBAR -->
                <?php get_sidebar("page"); ?>

        	</div> <!-- #main -->
        </div> <!-- #main-container -->

<?php get_footer(); ?>
